
package com.scs.application.modules.msg.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.msg.entity.Template;
import com.scs.application.modules.msg.mapper.TemplateMapper;
import com.scs.application.modules.msg.request.TemplateQueryRequest;
import com.scs.application.modules.msg.service.TemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 消息模板 service 实现
*
*/
@Slf4j
@Service
public class TemplateServiceImpl extends BaseServiceImpl<TemplateMapper, Template> implements TemplateService {

    @Override
    public List<Template> list(TemplateQueryRequest request) {
        List<Template> list = this.list(Wrappers.<Template>query()
                .eq(StringUtils.isNotBlank(request.getType()), "type", request.getType())
                .eq(StringUtils.isNotBlank(request.getCode()), "code", request.getCode())
                .like(StringUtils.isNotBlank(request.getTitle()), "title", request.getTitle())
            .orderByDesc("gmt_modified")
        );
        return list;
    }

    @Override
    public IPage<Template> page(TemplateQueryRequest request) {
        IPage page = this.page(request.getPage(), Wrappers.<Template>query()
                .eq(StringUtils.isNotBlank(request.getType()), "type", request.getType())
                .eq(StringUtils.isNotBlank(request.getCode()), "code", request.getCode())
                .like(StringUtils.isNotBlank(request.getTitle()), "title", request.getTitle())
            .orderByDesc("gmt_modified")
        );
        return page;
    }
}
